﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using OplugFramework.Configuration;
using OplugFramework.Web;

namespace OplugFramework.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class OplugFrameworkDbContextFactory : IDesignTimeDbContextFactory<OplugFrameworkDbContext>
    {
        public OplugFrameworkDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<OplugFrameworkDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            OplugFrameworkDbContextConfigurer.Configure(builder, configuration.GetConnectionString(OplugFrameworkConsts.ConnectionStringName));

            return new OplugFrameworkDbContext(builder.Options);
        }
    }
}
